#include <stdio.h>
#include <stdint.h>
#include <string.h>

/* 截取从n开始到结束的字符串 */
void substring(char *dest, const char *src, uint8_t n)
{
    uint8_t len = strlen(src);
    if (n >= len)
    {
        dest[0] = '\0'; // Handle out-of-bounds n
        return;
    }
    uint8_t i;
    for (i = n; i < len; i++)
    {
        dest[i - n] = src[i]; // Copy to dest starting at index 0
    }
    dest[i - n] = '\0'; // Proper null termination
}

int main()
{
    char *s = "Hello, World!\n"; // 定义字符串变量s，并初始化为"Hello, World!\n"
    printf("%s", s);             // 输出字符串s
    printf("\nHello2,\n World!\n");
    int a = 1;
    printf("address of a: 0x%p\n", &a); // 输出变量a的地址
    void *ptr = 0;
    printf("占字节数: %d 字节\n", (int)sizeof(ptr));           // 输出指针变量ptr的大小（字节数）
    int b[] = {1, 3, 5, 7, 9};                                 // 定义整数数组b，并初始化为1,3,5,7,9
    printf("数组大小: %d\n", (int)(sizeof(b) / sizeof(b[0]))); // 输出数组b的大小（元素个数）
    a = 8;
    printf("最低有效位MSB权重: %d\n", a & (-a));

    uint8_t *up;
    char *ss = "t-2";
    up = (char *)ss;
    char des[] = "";
    substring(des, ss, 2);
    printf("%s\n", des);
    printf("%s\n", up);
    printf("%d\n", strlen(up));
    printf("%c\n", up[0]);
    printf("%c\n", up[1]);
    printf("%c\n", up[2]);
    return 0;
}